Coding Example

The below is a good code sample that demonstrates both the coding and commenting standards that should be used.

import com.Navis.external.edi.entity.AbstractEdiPostInterceptor

import com.Navis.argo.business.reference.RoutingPoint

import com.Navis.framework.portal.UserContext

import com.Navis.argo.ContextHelper

import com.Navis.argo.business.api.ArgoUtils

import com.Navis.argo.BlTransactionsDocument

import org.apache.xmlbeans.XmlObject

import com.Navis.framework.util.BizViolation

import org.apache.commons.lang.StringUtils

/**

* <Purpose>

*

* Author: <a href="mailto:[email protected]">

Your Name</a>

* Date: ${DATE} : ${TIME}

* JIRA: <Specify the JIRA tracking number>

* SFDC: <Specify the Salesforce tracking number>

* Called from: <Specify from where this groovy is called>

*/

public class NavisSampleUpdateCommodityDescription extends AbstractEdiPostInterceptor

{

private static final String FUNCTION_DELETE = "DELETE"; // To avoid issues in N4 2.4, remove either static or final modifier

private static String FUNCTION_UPDATE = "UPDATE";

private Double _manifestedQty = null;

private RoutingPoint _pol = null;

String BLREL_DISPOSITION_CODE = "309";

List<String> CUSTOMS_INBOUND_QUANTITY_INCLUDE_LIST = new ArrayList<String>();

List<String> CUSTOMS_INBOUND_QUANTITY_EXCLUDE_LIST = new ArrayList<String>();

UserContext userContext = ContextHelper.getThreadUserContext();

Date timeNow = ArgoUtils.convertDateToLocalDateTime(ArgoUtils.timeNow(), userContext.getTimeZone());

/**

  * Implement logic for beforeEdiPost

  * @param sessionGkey The EDI session Gkey

  * @param xmlObject

  * @throws BizViolation

  */

public void beforeEdiPost(Serializable sessionGkey, XmlObject xmlObject) throws BizViolation

{

   log("************************************************************");

   log(" NavisSampleUpdateCommodityDescription before edi post started " + timeNow);

   assignBlProperties(xmlObject);

   log(" NavisSampleUpdateCommodityDescription before edi post ended " + timeNow);

}

private void assignBlProperties(XmlObject xmlObject)

{

  boolean isTargetMessageFunction = true;

   if (BlTransactionsDocument.class.isAssignableFrom(xmlObject.getClass()))

   {

    BlTransactionsDocument billOfLading = (BlTransactionsDocument)xmlObject;

    final BlTransactionsDocument.BlTransactions allBillOfLadingTransactions = billOfLading.getBlTransactions();

    final BlTransactionsDocument.BlTransactions billOfLadingTransaction = allBillOfLadingTransactions.getBlTransactionArray(0);

    String messageFunction = billOfLadingTransaction.xmlText();

    if (StringUtils.isNotEmpty(messageFunction) && !StringUtils.equals(messageFunction, FUNCTION_UPDATE))

    {

      isTargetMessageFunction = false;

    }

    /*

    Rest of logic goes here!

    */

   }

}

  // Implement logic for after EDI post

  // @param sessionGkey EDI session Gkey

  // @param xmlTransactionDocument XML Transaction Document

  // @param hibernatingEntity Hibernating Entity

  //

public void afterEdiPost(Serializable sessionGkey, XmlObject xmlTransactionDocument, HibernatingEntity hibernatingEntity)

{

   log("NavisSampleUpdateCommodityDescription after EDI post started " + timeNow);

   updateMarksAndNumber(xmlTransactionDocument);

   BillOfLading billOfLading = updateBillOfLadingProperties(xmlTransactionDocument);

   if (billOfLading == null)

   {

    billOfLading = findBillOfLading(xmlTransactionDocument);

   }

   if (billOfLading != null)

   {

     FlagType flag = FlagType.findFlagType("CUSTOMS RELEASE INFORMATIONAL DISPOSITION");

     log(" flag value: " + flag.toString());

     BlRelease billOfLadingRelease = createBLRelease(billOfLading, billOfLading.getBlManifestedQty(), flag, null);

   }

  // Need to update Inbound status if:

  // Bill of Lading inbound status = NULL AND

  // There is no Bill of Lading Release for disposition code 309 AND

  // There is no Bill of Lading Release for ACTIVE 1J

  // Then verify the quantity "quantity" to update the inbound status

  //

  log("Verify to update inbound status");

  if (billOfLading != null)

  {

   if (billOfLading.getBlInbond() != null)

   {

    List<BlRelease> blReleases = findActive1J(billOfLading.getBlGkey());

    if (!blReleases.isEmpty())

    {

     BlRelease billOfLadingRelease = getMostRecentBlReleaseOfDispCode(billOfLading.getPrimaryKey(), "309");

     log("Bill of Lading Inbound is null, Active 1J exists and no Bill of Lading Release disp code 309");

     checkAndUpdateInboundStatus(billOfLading);

    }

   }

  }

  log("NavisSampleUpdateCommodityDescription after EDI post ended " + timeNow);

}

}

//It should be as Navis standard

if (a < 5) {

   .. Do stuff

}

//Should not be written as below

if (a < 5)

{

   .. Do stuff

}